﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.CollectionsUI {
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import flash.filters.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;

    public class CollectionPanelPopoutView extends GenericDialogView {

        protected var m_mainPanel:JPanel;
        protected var m_collectionHeader:JTextField;
        protected var m_collectionHeaderPanel:JPanel;
        protected var m_gridList:GridList;
        protected var m_cellFactory:GridListCellFactory;
        protected var m_model:VectorListModel;
        protected var m_initialized:Boolean = false;

        public function CollectionPanelPopoutView(_arg1:Dictionary, _arg2:String="", _arg3:String="", _arg4:int=0, _arg5:Function=null){
            super(_arg1, _arg2, _arg3, _arg4, _arg5);
        }
        override protected function init():void{
            m_bgAsset = m_assetDict["collectionFlyout"];
            this.makeBackground();
            this.makeCenterPanel();
            ASwingHelper.prepare(this);
        }
        override protected function makeBackground():void{
        }
        override protected function makeCenterPanel():void{
            this.m_mainPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, -15);
            this.m_collectionHeaderPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.RIGHT);
            this.m_collectionHeader = ASwingHelper.makeTextField("", EmbeddedArt.TITLE_FONT, 12, 0xFFFFFF);
            this.m_collectionHeaderPanel.append(this.m_collectionHeader);
            this.m_collectionHeaderPanel.setPreferredHeight(CollectionPanelPopout.NAME_HEIGHT);
            ASwingHelper.prepare(this.m_collectionHeaderPanel);
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel();
            this.m_model = new VectorListModel();
            this.m_cellFactory = new CollectionItemCellFactory(new IntDimension(CollectionPanelPopout.SLOT_SIDE_LENGTH, CollectionPanelPopout.SLOT_SIDE_LENGTH));
            this.m_gridList = new GridList(this.m_model, this.m_cellFactory, CollectionPanelPopout.MAX_SLOTS, 1);
            this.m_gridList.setPreferredHeight(m_bgAsset.height);
            this.m_gridList.setPreferredWidth(m_bgAsset.width);
            _local1.appendAll(ASwingHelper.horizontalStrut(CollectionPanelPopout.GRID_MARGIN), this.m_gridList, ASwingHelper.horizontalStrut(CollectionPanelPopout.GRID_MARGIN));
            var _local2:MarginBackground = new MarginBackground(m_bgAsset);
            _local1.setBackgroundDecorator(_local2);
            ASwingHelper.prepare(_local1);
            this.m_mainPanel.append(_local1);
            this.m_mainPanel.append(this.m_collectionHeaderPanel);
            ASwingHelper.prepare(this.m_mainPanel);
            this.append(this.m_mainPanel);
            ASwingHelper.prepare(this);
            this.m_initialized = true;
        }
        public function prepopulatePanelSlots(_arg1:Collection):void{
            var _local5:CollectionItemCell;
            var _local6:Item;
            this.m_collectionHeader.setText(_arg1.localizedName);
            var _local2:TextFormat = new TextFormat();
            _local2.align = TextFormatAlign.RIGHT;
            _local2.size = 18;
            TextFieldUtil.formatSmallCaps(this.m_collectionHeader.getTextField(), _local2);
            this.m_collectionHeader.filters = [new GlowFilter(0)];
            this.m_collectionHeaderPanel.setPreferredHeight((this.m_collectionHeader.getTextField().textHeight + 5));
            ASwingHelper.prepare(this.m_collectionHeaderPanel);
            ASwingHelper.prepare(this.m_mainPanel);
            ASwingHelper.prepare(this);
            var _local3:int;
            while (_local3 < this.m_model.getSize()) {
                _local5 = (this.m_gridList.getCellByIndex(_local3) as CollectionItemCell);
                _local5.forceFadeComplete();
                _local3++;
            };
            this.m_model.clear();
            var _local4:Array = _arg1.getCollectableNames();
            _local3 = 0;
            while (_local3 < CollectionPanelPopout.MAX_SLOTS) {
                if (_local3 < _local4.length){
                    _local6 = Global.gameSettings.getItemByName(_local4[_local3]);
                    if (_local6){
                        this.m_model.append(_local6);
                    };
                };
                _local3++;
            };
        }
        public function invalidateData():void{
            var _local1:int;
            var _local2:CollectionItemCell;
            if (this.m_initialized){
                _local1 = 0;
                while (_local1 < this.m_model.getSize()) {
                    _local2 = (this.m_gridList.getCellByIndex(_local1) as CollectionItemCell);
                    _local2.invalidateData();
                    _local1++;
                };
            };
        }
        public function invalidateCell(_arg1:String, _arg2:Collection):void{
            var _local3:int = this.getCollectableNumber(_arg1, _arg2);
            var _local4:CollectionItemCell = (this.m_gridList.getCellByIndex(_local3) as CollectionItemCell);
            _local4.invalidateData();
        }
        protected function getCollectableNumber(_arg1:String, _arg2:Collection):int{
            return (_arg2.getCollectableNames().indexOf(_arg1));
        }
        public function playFadeIn(_arg1:String, _arg2:Collection, _arg3:Function, _arg4:Function):void{
            var _local5:int = this.getCollectableNumber(_arg1, _arg2);
            var _local6:CollectionItemCell = (this.m_gridList.getCellByIndex(_local5) as CollectionItemCell);
            _local6.playFadeIn(_arg3, _arg4);
        }

    }
}//package Display.CollectionsUI 
